// 部门select框
<style lang="less" scoped>
</style>
<template>
  <Select @on-change="sendData"
          clearable
          filterable
          v-model="area"
          placeholder="请选择部门">
    <Option v-for="item in areaList"
            :value="item"
            :key="item">{{ item }}</Option>
  </Select>
</template>
<script>
import { ajaxPost } from 'global/axios';
import storage from 'good-storage';
export default {
  data() {
    return {
      urlAddressList: '/sys/department/distinct',
      area: '',
      areaList: [],
    };
  },
  methods: {
    getAddress() {
      let params = {
        data: {
          searchValue: {
            type: '0',
          },
          fieldName: 'dep_name',
          type: 'String',
        },
        token: storage.session.get('token'),
        url: this.urlAddressList,
        success: res => {
          this.areaList = res.data.result;
        },
      };
      if (storage.session.get('level') == '2') {
        params.data.searchValue.level2 = storage.session.get('dep_name');
      } else if (storage.session.get('level') == '3') {
        params.data.searchValue.level3 = storage.session.get('dep_name');
      } else if (storage.session.get('level') == '1') {
        params.data.searchValue.level1 = storage.session.get('dep_name');
      }
      ajaxPost(params);
    },
    sendData(data) {
      this.$emit('getData', data);
    },
  },
  mounted() {
    this.getAddress();
  },
};
</script>

